package com.enation.app.javashop.api.client;

import com.enation.app.javashop.model.shop.dos.ShipTemplateDO;
import com.enation.app.javashop.model.shop.vo.ShipTemplateVO;
import com.enation.app.javashop.service.shop.ShipTemplateManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * @author fk
 * @version v2.0
 * @Description:
 * @date 2018/8/20 10:02
 * @since v7.0.0
 */
@RestController
@RequestMapping("/client/ship-template")
@Validated
@ApiIgnore
public class ShipTemplateClientController {


    @Autowired
    private ShipTemplateManager shipTemplateManager;

    @GetMapping("/{id}")
    public ShipTemplateDO getModel(@PathVariable("id") Long id) {
        return shipTemplateManager.getFromCache(id);
    }


    @RequestMapping(value = "/{id}/scripts", method = RequestMethod.GET)
    public List<String> getScripts(@PathVariable("id") Long id){
        return shipTemplateManager.getScripts(id);
    }

    /**
     * 新增运费模板的时候，生成script缓存到redis
     *
     * @param shipTemplateVO 运费模板
     */
    @RequestMapping(value = "/scripts", method = RequestMethod.POST)
    public void cacheShipTemplateScript(@RequestBody ShipTemplateVO shipTemplateVO){

        this.shipTemplateManager.cacheShipTemplateScript(shipTemplateVO);
    }

}
